<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use DB;
use Exception;

/**
 * Class NoviceTaskRecord
 *
 * @package App
 * @mixin \Eloquent
 */
class NoviceTaskRecord extends Model
{
    protected $table = "novice_task_record";
    public $timestamps = false;

    const TYPE_MOBILE = 1;
    const TYPE_SIGN = 2;
    const TYPE_WITHDRAW = 3;
    const TYPE_RUNGAMINNG = 4;
    const TYPE_DAILY = 5;

    static $TypeDisplay = [
        self::TYPE_MOBILE => '手机号验证',
        self::TYPE_SIGN => '签到',
        self::TYPE_WITHDRAW => '提现',
        self::TYPE_RUNGAMINNG => '跑步游戏',
        self::TYPE_DAILY => '日常任务',
    ];


    /**
     * 添加记录
     * @param $user_id
     * @param $type
     * @return array
     */
    static function RecordPublish($user_id, $type)
    {
        if (!NoviceTaskRecord::where('user_id', $user_id)->where('type', $type)->exists()) {
            try {
                $result = DB::table('novice_task_record')->insert([
                    'user_id' => $user_id,
                    'title' => '完成提现任务',
                    'type' => $type,
                    'create_time' => date('Y-m-d H:i:s'),
                ]);
                if (!$result) {
                    return ['status' => 2, 'message' => '失败'];
                }
            } catch (Exception $exception) {
                logger($exception);
                return ['status' => 2, 'message' => '失败'];
            }

        }

        return ['status' => 1, 'message' => '成功'];
    }
}
